let v = new Vue({
    el:'#app',
    data:{
        userId:'',
        article:{
            id:''
        },
        users:[]
    },
    methods:{
        findArticleDetail:function (){
            axios(`article/findArticleDetail/${this.article.id}/${this.userId}`)
                .then(response=>{
                    if (response.data.flag){
                        this.article = response.data.data.article;
                        this.users = response.data.data.users;
                    }
                })
        },
        updateBrowseCount:function (){
            axios(`article/updateBrowseCount/${this.article.id}`);
        },
        toUserDetail:function (uid){
            sessionStorage.setItem("userId",uid);
        },
        updateCollect:function (id,collect){
            //取反
            collect = !collect;
            axios.put(`article/updateCollect/${this.article.id}/${this.userId}/${collect}`)
                .then(response=>{
                    if (response.data.flag){
                        if(collect){
                            layer.msg("收藏成功");
                        }else{
                            layer.msg("取消收藏成功");
                        }
                        //刷新页面
                        this.findArticleDetail();
                    }
                })
        }
    },
    created:function (){
        this.userId = sessionStorage.getItem("myId");
        this.article.id = sessionStorage.getItem("aid");
        this.findArticleDetail();
        this.updateBrowseCount();
    }
})